package communicationMessages;

import java.util.Vector;
import java.util.logging.Level;

import logger.LoggerWriter;
import data.Forum;
import data.MemberDataBase;
import database.DB;


public class DeleteSubForumMessage extends Message {

	@Override
	public String getAnswer() {
		String[] arr = this.content.split(delimiter);
		LoggerWriter logger = LoggerWriter.getLoggerWriter();
		String ans ="SubForumDeleted"+delimiter;
		if (arr.length != 2)
		{
			logger.log("failed"+delimiter +"DeleteSubForum Message wrong format"+delimiter, Level.WARNING);
			ans = "failed"+delimiter +"DeleteSubForum Message wrong format"+delimiter;
		}
		else
		{
			String userName, subForumId ;
			userName = arr[0];
			subForumId = arr[1];
			if (DB.isAdmin(userName) && DB.isSubForumExist(subForumId))
			{
				DB.deleteSubForum(subForumId);
				ans += "admin"+delimiter +"Success"+delimiter ;
			}
				
		}
		return ans;
	}
	
//	String userName, subForumId ;
//	userName = arr[0];
//	subForumId = arr[1];
//	int subForumInt = Integer.valueOf(subForumId);
//	Vector<Integer> path = new Vector<Integer>();
//	path.add(subForumInt);
//	Forum forum = Forum.getForum();
//	int userId = MemberDataBase.getMembersDataBase().getMember(userName).get_id();
//	Boolean answer =  forum.deleteSubForum(userId, subForumInt);
//	if (answer)
//	ans += MemberDataBase.getUserRoll(userName)+delimiter +"Success"+delimiter ;
//	else
//		ans += MemberDataBase.getUserRoll(userName)+delimiter +"Failed"+delimiter ;

}
